<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>CCI升贴水速算</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body{font-family:Arial,Helvetica,sans-serif;margin:0;padding:20px;background:#f5f5f5}
h2{margin:0 0 10px}
.row{margin:8px 0}
input[type=number]{width:100px;padding:6px}
button{padding:8px 16px;background:#007bff;color:#fff;border:0;border-radius:4px}
#result{font-size:24px;font-weight:bold;margin-top:15px}
</style>
</head>
<body>
<h2>北方港动力煤交割价</h2>
<div class="row">前日CCI5500 (元/t) <input id="idP" type="number" value="700"></div>
<div class="row">收到基低位热值 <input id="idQ" type="number" value="5000"> kcal/kg</div>
<div class="row">干燥基全硫 <input id="idS" step="0.01" type="number" value="0.9"> %</div>
<div class="row">全水分 <input id="idM" step="0.1" type="number" value="26"> %</div>
<button onclick="go()">计算</button>
<div id="result">
  升贴水：<span id="outDelta">---</span> 元/t<br>
  结算价：<span id="outSettle">---</span> 元/t
</div>
<script>
function go(){
  const P = +idP.value, Q = +idQ.value, S = +idS.value, M = +idM.value;
  let cq = Q<4300? 0.7687/4500*Q*0.5 :
           Q<4800? 0.7687/4500*Q :
           Q<5300? 0.8768/5000*Q :
                   Math.min(Q,6000)/5500;
  const dq = P*(cq-1);
  const ds = S<=0.8? 0 : -4*Math.round((S-0.8)/0.1*10)/10;
  const dm = -P*Math.max(0,Math.round((M-25)*10)/10)/100;
  const delta = Math.round((dq+ds+dm)*100)/100;
  const settle = Math.round((P+delta)*100)/100;
  outDelta.textContent = delta.toFixed(2);
  outSettle.textContent = settle.toFixed(2);
}
</script>
</body>
</html>